<div id="required_fields_message"><?php echo $this->lang->line('common_fields_required_message'); ?></div>
<ul id="error_message_box"></ul>
<?php
echo form_open('staffs/save_payroll/'.$person_id,array('id'=>'payroll_form'));
?>
<fieldset id="item_basic_info">
<legend><?php echo $this->lang->line("staffs_payroll_info"); ?></legend>

<div class="field_row clearfix">	
<?php echo form_label($this->lang->line('staffs_basic_wage').':', 'basic_wages',array('class'=>'required wide')); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'basic_wages',
		'id'=>'basic_wages',
		'value'=>'0')
	);?>
	</div>
</div>

<div class="field_row clearfix">	
<?php echo form_label($this->lang->line('staffs_tax_cat').':', 'tax_cat',array('class'=>'wide')); ?>
	<div class='form_field'>
	<?php echo form_dropdown('tax_cat', $taxs);?>
	</div>
</div>

<div class="field_row clearfix">	
<?php echo form_label($this->lang->line('staffs_ssf_cat').':', 'ssf_cat',array('class'=>'wide')); ?>
	<div class='form_field'>
	<?php echo form_dropdown('ssf_cat', $ssfs);?>
	</div>
</div>

<div class="field_row clearfix">
		<?php echo form_label($this->lang->line('date').':', 'payroll_date',array('class'=>'required wide')); ?>
		<div class='form_field'>
		<?php echo form_input(array(
		'name'=>'payroll_date',
		'id'=>'payroll_date',
		'value'=>date('F d, Y'))
		);?>
		
		<?php
			echo form_button(array(
			'name'=>'payroll_date_btn',
			'id'=>'payroll_date_btn',
			'class'=>'submit_button'),$this->lang->line('date')
			);
		?>
		</div>
		<script type="text/javascript">
                  new Calendar({
                          inputField: "payroll_date",
                          dateFormat: "%B %d, %Y",
                          trigger: "payroll_date_btn",
                          bottomBar: true,
						  showTime: false,
						  animation: true,
                          onSelect: function() {
                              this.hide();
                          }
						 });
                </script>
</div>


<fieldset id="item_basic_info">
<legend><?php echo $this->lang->line("staffs_allowances"); ?></legend>
<div class="field_row clearfix">	
<?php echo form_label($this->lang->line('_ssf_1').':', 'ssf_percent_1',array('class'=>'wide')); ?>
	<div class='form_field'>
	Description
	<?php echo form_input(array(
		'name'=>'allowance_name[]',
		'id'=>'allowance_name',
		'value'=> '')
	);?>
	</div>
	<div class='form_field'>
	Amount
	<?php echo form_input(array(
		'name'=>'allowance_amount[]',
		'id'=>'allowance_amount',
		'size'=>'8',
		'value'=> '0'));?>
	</div>
	<div class='form_field'>
	Taxable
		<?php echo form_checkbox('taxable1', '1', TRUE);?>
	</div>
</div>

<div id="allowance_inner"></div>

<div class="field_row clearfix">	
	<div class='form_field'>
	<?php echo form_hidden('theallowanceValue',0);?>
	</div>
</div>
<?php 	
echo form_button(array(
	'name'=>'allowance_more_btn',
	'id'=>'allowance_more_btn',
	'onclick'=>'allowance_add_field();',
	'class'=>'submit_button float_right'),$this->lang->line('common_add_more')
);
echo form_button(array(
	'name'=>'allowance_remove_btn',
	'id'=>'allowance_remove_btn',
	'onclick'=>'allowance_remove_field();',
	'class'=>'submit_button float_right'),$this->lang->line('common_remove')
);
?>
</fieldset>

<fieldset id="item_basic_info">
<legend><?php echo $this->lang->line("staffs_deductions"); ?></legend>
<div class="field_row clearfix">	
<?php echo form_label($this->lang->line('_ssf_1').':', 'ssf_percent_1',array('class'=>'wide')); ?>
	<div class='form_field'>
	Description
	<?php echo form_input(array(
		'name'=>'deductions_name[]',
		'id'=>'deductions_name',
		'value'=> '')
	);?>
	</div>
	<div class='form_field'>
	Amount
	<?php echo form_input(array(
		'name'=>'deductions_amount[]',
		'id'=>'deductions_amount',
		'size'=>'8',
		'value'=> '0'));?>
	</div>
</div>

<div id="deductions_inner"></div>

<div class="field_row clearfix">	
	<div class='form_field'>
	<?php echo form_hidden('thedeductionsValue',0);?>
	</div>
</div>
<?php 	
echo form_button(array(
	'name'=>'deductions_more_btn',
	'id'=>'deductions_more_btn',
	'onclick'=>'deductions_add_field();',
	'class'=>'submit_button float_right'),$this->lang->line('common_add_more')
);
echo form_button(array(
	'name'=>'deductions_remove_btn',
	'id'=>'deductions_remove_btn',
	'onclick'=>'deductions_remove_field();',
	'class'=>'submit_button float_right'),$this->lang->line('common_remove')
);
?>
</fieldset>
<?php
echo form_submit(array(
	'name'=>'submit',
	'id'=>'submit',
	'value'=>$this->lang->line('common_submit'),
	'class'=>'submit_button float_right')
);
?>
</fieldset>
<?php 
echo form_close();
?>
<script type='text/javascript'>
//validation and submit handling
$(document).ready(function()
{	
	$('#payroll_form').validate({
		submitHandler:function(form)
		{
			$(form).ajaxSubmit({
			success:function(response)
			{
				tb_remove();
				post_item_form_submit(response);
			},
			dataType:'json'
		});

		},
		errorLabelContainer: "#error_message_box",
 		wrapper: "li",
		rules: 
		{
			basic_wages:"required",
			payroll_date:"required"
   		},
		messages: 
		{
			basic_wages:"<?php echo $this->lang->line('staffs_basic_wage_required'); ?>",
			payroll_date:"<?php echo $this->lang->line('staffs_payroll_date_required'); ?>"
		}
	});
});


function allowance_add_field()
	{	
		var inner_DIV = document.getElementById('allowance_inner');
		var numi = document.getElementById('theallowanceValue');
		var num = (numi.value -1)+ 2;
		numi.value = num;
		var order_value = num + 1;
		var newdiv = document.createElement('div');
		var divIdName = 'my'+num+'Div';
		newdiv.setAttribute('id',divIdName);
		newdiv.setAttribute('name',divIdName);
		newdiv.setAttribute('class','formw');
		newdiv.innerHTML = '<div class="field_row clearfix"><label for="" class="required wide">:</label><div class=\'form_field\'>Description<input id=\'allowance_name[]\' value=\'\' name=\'allowance_name[]\' type=\'text\'></div>&nbsp;<div class=\'form_field\'>Amount<input id=\'allowance_amount[]\' name=\'allowance_amount[]\' type=\'text\' size=\'8\' value=\'0\'>Taxable<input name="taxable'+order_value+'" value="1" checked="checked" type="checkbox"></div></div>';
		inner_DIV.appendChild(newdiv);
	}
	
	function allowance_remove_field()
	{
		var numi = document.getElementById('theallowanceValue');
		var divIdName = 'my'+numi.value+'Div';
		
		var num = (numi.value -1);
		numi.value = num;
		
		var d = document.getElementById('allowance_inner');
		var olddiv = document.getElementById(divIdName);
		d.removeChild(olddiv);
	}
	
	
	function deductions_add_field()
	{	
		var inner_DIV = document.getElementById('deductions_inner');
		var numi = document.getElementById('thedeductionsValue');
		var num = (numi.value -1)+ 2;
		numi.value = num;
		var order_value = num + 1;
		var newdiv = document.createElement('div');
		var divIdName = 'my'+num+'Div';
		newdiv.setAttribute('id',divIdName);
		newdiv.setAttribute('name',divIdName);
		newdiv.setAttribute('class','formw');
		newdiv.innerHTML = '<div class="field_row clearfix"><label for="" class="required wide">:</label><div class=\'form_field\'>Description<input id=\'deductions_name[]\' value=\'\' name=\'deductions_name[]\' type=\'text\'></div>&nbsp;<div class=\'form_field\'>Amount<input id=\'deductions_amount[]\' name=\'deductions_amount[]\' type=\'text\' size=\'8\' value=\'0\'></div></div>';
		inner_DIV.appendChild(newdiv);
	}
	
	function deductions_remove_field()
	{
		var numi = document.getElementById('thedeductionsValue');
		var divIdName = 'my'+numi.value+'Div';
		
		var num = (numi.value -1);
		numi.value = num;
		
		var d = document.getElementById('deductions_inner');
		var olddiv = document.getElementById(divIdName);
		d.removeChild(olddiv);
	}
	
</script>
